import 'dart:io';

import 'package:dio/dio.dart';

import 'Api.dart';

class FileUploadUtil {
  /// 上传照片
  static Future<String?> uploadImage(File file, ProgressCallback progressCallback) async {
    Map<String,dynamic> params = {};
    params["file"] = await MultipartFile.fromFile(file.path);

    Dio dio = Dio();
    dio.options.contentType='application/json';
    Response response = await dio.post(
      Api.baseUrl + Api.fileUpload,
      data: FormData.fromMap(params),
      onSendProgress: progressCallback,
    );
    if (response.statusCode == 200) {
      return response.data;
    } else {
      return null;
    }
  }
}

class FileModel {
  File file; // 文件
  int progress; // 上传进度
  int total; // 上传总进度
  String url; // 上传完成图片地址

  FileModel({
    required this.file,
    this.progress = 0,
    this.total = 0,
    this.url = '',
  });
}